package dissertation.common.utils.applicationxml.builder;

import dissertation.common.utils.applicationxml.decorator.ApplicationXMLDecoratorV30;
import dissertation.common.utils.applicationxml.decorator.IApplicationXMLDecorator;

import java.util.List;

/**
 * ApplicationXMLBuilder for EJB 3.0
 */
public class ApplicationXMLBuilderV30 implements IApplicationXMLBuilder {
    private IApplicationXMLDecorator applicationXMLDecorator;

    /**
     * No-arg constructor for instantiating the builder
     */
    public ApplicationXMLBuilderV30() {
        applicationXMLDecorator = new ApplicationXMLDecoratorV30();
    }

    /**
     * Builder method
     * @param jarNames - list of jar names
     * @return - result string
     */
    @Override
    public String buildApplicationXML(List<String> jarNames) {
        StringBuilder sb = new StringBuilder();
        if (jarNames != null) {
            for (String jarName : jarNames) {
                sb.append(applicationXMLDecorator.decorateWithModuleTag(jarName));
            }
        }
        return applicationXMLDecorator.decorateWithRootTag(sb.toString());
    }
}
